home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / myPlatform demo ƒ / sHMovPlatform.c < prev    next >
Text File  |  1995-01-16  |  2KB  |  89 lines

  1. /* */
  2.  
  3. /* */
  4.  
  5. #include"SAT.h"
  6. #include "myPlatform.h"
  7.  
  8. extern FacePtr    platFace; /* Global from sMovPlatform.c */
  9.  
  10. void InitHMovPlatform()
  11. {
  12. }
  13.  
  14. pascal void SetupHMovPlatform(SpritePtr me)
  15. {
  16.     Rect            r;
  17.     PolyHandle    pol;
  18.     
  19.     me->speed.h = -1 + SATRand(2) * 2;
  20.     /*me->kind = -2; */
  21.     me->face = platFace; 
  22.     SetRect(&(me->hotRect), 0, 3, 60, 20);
  23.     me->task = &HandleHMovPlatform;
  24.     me->hitTask = &HitHMovPlatform;
  25. }
  26.  
  27. pascal void HandleHMovPlatform(SpritePtr me)
  28. {
  29.     me->position.h = me->position.h + me->speed.h;
  30.     if(me->position.h < 40)
  31.         me->speed.h = 1;
  32.     if(me->position.h > (gSAT.offSizeH - 100))
  33.         me->speed.h = -1;
  34.  
  35.     if(me->speed.h == 0){
  36.         if(me->position.h > gSAT.offSizeH/2)
  37.             me->speed.h = -1;
  38.         else
  39.             me->speed.h = 1;
  40.     }
  41.     me->layer = -me->position.v;
  42. }
  43.  
  44. pascal void HitHMovPlatform(SpritePtr me, SpritePtr him)
  45. {
  46.     int     mini, i, min;
  47.     int    diff[5];
  48.     
  49.     if(him->task != HandlePlatform) {
  50.         diff[1] = -me->hotRect2.top + (him->hotRect2.bottom);            /* TtoB */
  51.         diff[2] = -him->hotRect2.top + (me->hotRect2.bottom);            /* BtoT */
  52.         diff[3] = -me->hotRect2.left + (him->hotRect2.right);            /* LtoR */
  53.         diff[4] = -him->hotRect2.left + (me->hotRect2.right);            /* RtoL */
  54.         mini = 0;
  55.         min = 10000;
  56.         for(i = 1; i <= 4; i++)
  57.             if(min > diff[i]){
  58.                     min = diff[i];
  59.                     mini = i;
  60.             }
  61.         switch(mini){
  62.             case 1: 
  63.                     him->position.v = him->position.v - diff[1] + 1;
  64.                     him->position.h = him->position.h + me->speed.h; 
  65.                     him->kind = 10; 
  66.                     if(him->speed.v > 0)
  67.                         him->speed.v = 0;
  68.                     break;
  69.             case 2: 
  70.                     him->position.v = him->position.v + diff[2] + 1;
  71.                     if(him->speed.v < 0)
  72.                         him->speed.v = -him->speed.v;
  73.                     break;
  74.             case 3: 
  75.                     him->position.h = him->position.h - diff[3] - 1;
  76.                     him->kind = 10;
  77.                     if(him->speed.h > 0)
  78.                         him->speed.h = -him->speed.h;
  79.                     break;
  80.             case 4: 
  81.                     him->position.h = him->position.h + diff[4] + 1;
  82.                     him->kind = 10; 
  83.                     if(him->speed.h < 0)
  84.                         him->speed.h = -him->speed.h;
  85.                     break;
  86.         } /* switch */
  87.     } /* if */
  88. }
  89.